import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Demo2 {
    public static void main(String[] args) {
        // 注意：
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 5, 3, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy() //拒绝策略
        );
        try {
            for (int i=1; i<=80; i++){
                //使用线程池之后创建线程
                threadPoolExecutor.execute(()->{
                    System.out.println(Thread.currentThread().getName()+ " ok");
                });
            }
        } finally {
            threadPoolExecutor.shutdown();
        }
    }

}
